<template>
  <el-form ref="formRef" :model="form" label-width="120px" status-icon>
    <el-form-item label="公众号名称" prop="mp_name">
      <el-input v-model="form.mp_name" placeholder="请输入公众号名称" />
    </el-form-item>
    <el-form-item label="原始ID" prop="origin_id">
      <el-input v-model="form.origin_id" placeholder="请输入原始ID" />
    </el-form-item>
    <el-form-item label="公众号二维码" prop="mp_qrcode">
      <KoiUploadImage v-model:imageUrl="form.mp_qrcode"></KoiUploadImage>
    </el-form-item>
    <el-form-item label="AppID" prop="app_id">
      <el-input v-model="form.app_id" placeholder="请输入AppID" />
    </el-form-item>
    <el-form-item label="AppSecret" prop="app_secret">
      <el-input v-model="form.app_secret" placeholder="请输入AppSecret" />
    </el-form-item>
    <el-form-item label="服务器URL" prop="server_url">
      <el-input v-model="form.server_url" />
    </el-form-item>
    <el-form-item label="Token" prop="token">
      <el-input v-model="form.token" />
    </el-form-item>
    <el-form-item label="EncodingAESKey" prop="encoding_aes_key">
      <el-input v-model="form.encoding_aes_key" />
    </el-form-item>
    <!--    <el-form-item label="业务域名" prop="encoding_aes_key">-->
    <!--      <el-input v-model="form.encoding_aes_key" />-->
    <!--    </el-form-item>-->
    <!--    <el-form-item label="JS接口安全域名" prop="encoding_aes_key">-->
    <!--      <el-input v-model="form.encoding_aes_key" />-->
    <!--    </el-form-item>-->
    <!--    <el-form-item label="网页授权域名" prop="encoding_aes_key">-->
    <!--      <el-input v-model="form.encoding_aes_key" />-->
    <!--    </el-form-item>-->
    <el-form-item>
      <el-button type="primary" v-auth="['colewechat:admin:config:edit']" plain v-debounce="handleSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { getConfig } from "@/api/system/config";

// 定义参数的类型
interface IConfigProps {
  configKey?: string;
  name?: string;
}

// 子组件接收父组件的值
// withDefaults：设置默认值  defineProps：接收父组件的参数
const props = withDefaults(defineProps<IConfigProps>(), {
  name: "",
  configKey: ""
});

onMounted(() => {
  getConfig({ key: props.configKey }).then(res => {
    if (Object.keys(res.data).length > 0) {
      resetForm();
      form.value = res.data;
    }
  });
});

// 当前组件获取父组件传递的事件方法
const emits = defineEmits(["handleSubmit"]);
// 弹框的确定事件
const handleSubmit = () => {
  emits("handleSubmit", form.value);
};

let form = ref<any>({
  mp_name: "",
  origin_id: "",
  mp_qrcode: "",
  appid: "",
  app_secret: "",
  server_url: "",
  token: "",
  encoding_aes_key: ""
});
const resetForm = () => {
  form.value = {
    mp_name: "",
    origin_id: "",
    mp_qrcode: "",
    appid: "",
    app_secret: "",
    server_url: "",
    token: "",
    encoding_aes_key: ""
  };
};
</script>

<style lang="scss" scoped></style>
